package contact.servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import contact.domain.ContactGroup;
import contact.domain.DAOContactGroup;


public class RemoveGroup extends HttpServlet {
	private static final long serialVersionUID = 8706797407609326696L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
		DAOContactGroup daoGroup = (DAOContactGroup) context.getBean("DAOContactGroup");
		try{
			Long id = new Long(request.getParameter("id"));
			ContactGroup group = daoGroup.read(id);
			daoGroup.delete(group);
		}
		catch(NumberFormatException e){}
		RequestDispatcher rd = request.getRequestDispatcher("/manageGroup.jsp");
		rd.forward(request, response);

	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

	}

}
